package argo.hot100.arr;

public class Rotate {


    public void rotate(int[] nums, int k) {
        if (nums == null || nums.length <= 1 || k <= 0) {
            return;
        }
        k = k % nums.length;
        int[] tmp = new int[k];
        int left = 0;

        for (int i = nums.length - k; i < nums.length; i++) {
            tmp[left] = nums[i];
            left++;
        }


        for (int i = nums.length - 1; i >= k; i--) {
            nums[i] = nums[i - k];
        }

        for (int i = 0; i < k; i++) {
            nums[i] = tmp[i];
        }


    }

    public void rotate1(int[] nums, int k) {
        if (nums == null || nums.length <= 1 || k <= 0) {
            return;
        }

        while (k > 0) {
            int p = nums[nums.length - 1];
            for (int i = nums.length - 1; i > 0; i--) {
                nums[i] = nums[i - 1];
            }
            nums[0] = p;
            k--;
        }

    }


}
